﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="Ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript" src="Scripts/common.js"></script>
<script type="text/javascript">
//    function createXmlHttp() {//创建xhr对象
//        var xhobj = false;
//        try {
//            xhobj = new ActiveXObject("Msxml2.XMLHTTP"); // ie msxml3.0+
//        } catch (e) {
//            try {
//                xhobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml2.6
//            } catch (e2) {
//                xhobj = false;
//            }
//        }
//        if (!xhobj ) {// Firefox, Opera 8.0+, Safari
//            xhobj = new XMLHttpRequest();
//        }
//        return xhobj;
    //    }

    var xhr;
    window.onload = function(){
        xhr = createXmlHttp();
        
    }

    function doAjax(){
        xhr.open("GET","Ajax.aspx?isAjax=1",true);
        xhr.onreadystatechange= watch;
        xhr.send(null);
        }
    
    function watch(){
        if (xhr.readyState >= 4) {
           if (xhr.status == 200) {
               var msg = xhr.responseText; //服务器返回的字符串
               document.getElementById("ajax").innerHTML = msg;
           } else alert("服务器错误!" + xhr.status);
       }

    }

</script>

<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <input type="button" value="ajax" onclick= "doAjax()" />
    
    <div id="ajax">
    
    </div>
    </form>
</body>
</html>
